package com.qd.panda.space;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.cdqidi.util.page.PageUtil;
import com.qd.common.panda.domain.entity.space.ParkSpaceDTO;
import com.qd.common.panda.domain.entity.space.ParkSpaceTenantDTO;
import com.qd.panda.service.space.ParkSpaceService;
import com.qd.panda.service.space.ParkSpaceTenantService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;
import java.util.List;

/**
 * 短期租赁/WEB_车位租赁信息
 *
 * @author sjk
 */
@RequiredArgsConstructor
@Validated
@RestController
@RequestMapping("/sys/parkSpace/")
@Slf4j
public class ParkSpaceController {
    private final ParkSpaceService parkSpaceService;
    private final ParkSpaceTenantService parkSpaceTenantService;

    /**
     * 租赁列表
     *
     * @param dto 查询参数以及页数和每页显示条数
     * @return 列表信息
     */
    @GetMapping(value = "/leasePage")
    public IPage<ParkSpaceDTO> page(ParkSpaceDTO dto) {
        return parkSpaceService.page(PageUtil.buildPage(dto),dto);
    }

    /**
     * 租赁详情
     * @param sid 租赁ID
     * @return 详情
     */
    @GetMapping(value = "/getLeaseById")
    public ParkSpaceDTO getById(@Validated @NotBlank(message = "租赁ID不能为空") String sid) {
        return parkSpaceService.getByIdDto(sid);
    }

    /**
     * 查询承租列表
     * @param sid 租赁ID
     * @return 列表
     */
    @GetMapping(value = "/tenantList")
    public List<ParkSpaceTenantDTO> tenantList(@Validated @NotBlank(message = "租赁ID不能为空") String sid) {
        return parkSpaceTenantService.getListBySidDto(sid);
    }

    /**
     * 查询承租详情
     * @param id 主键
     * @return 列表
     */
    @GetMapping(value = "/getTenantById")
    public ParkSpaceTenantDTO getTenantById(@Validated @NotBlank(message = "ID不能为空") String id) {
        return parkSpaceTenantService.getByIdDto(id);
    }

}